﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace CommunitySystemModel
{
    public class CheGaiModel
    {
        private bool isselected = false;
        [DataMember]
        public bool IsSelected
        {
            get { return isselected; }
            set { isselected = value; }
        }

        private int _ID;
        [DataMember]
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private int _EmpID;
        [DataMember]
        public int EmpID
        {
            get { return _EmpID; }
            set { _EmpID = value; }
        }

        private string _OldZhiJi = string.Empty;
        [DataMember]
        public string OldZhiJi
        {
            get { return _OldZhiJi; }
            set { _OldZhiJi = value; }
        }

        private string _OldJinE = string.Empty;
        [DataMember]
        public string OldJinE
        {
            get { return _OldJinE; }
            set { _OldJinE = value; }
        }

        private DateTime? _ChangeDate;
        [DataMember]
        public DateTime? ChangeDate
        {
            get { return _ChangeDate; }
            set { _ChangeDate = value; }
        }

        private string _Operator;
        [DataMember]
        public string Operator
        {
            get { return _Operator; }
            set { _Operator = value; }
        }

        private string _NewZhiJi = string.Empty;
        [DataMember]
        public string NewZhiJi
        {
            get { return _NewZhiJi; }
            set { _NewZhiJi = value; }
        }

        private string _NewJinE = string.Empty;
        [DataMember]
        public string NewJinE
        {
            get { return _NewJinE; }
            set { _NewJinE = value; }
        }

        private DateTime? _CreateDate;
        [DataMember]
        public DateTime? CreateDate
        {
            get { return _CreateDate; }
            set { _CreateDate = value; }
        }

        private string _Status = string.Empty;
        [DataMember]
        public string Status
        {
            get { return _Status; }
            set { _Status = value; }
        }

        private int _RelationID;
        [DataMember]
        public int RelationID
        {
            get { return _RelationID; }
            set { _RelationID = value; }
        }

        private string _Demo = string.Empty;
        [DataMember]
        public string Demo
        {
            get { return _Demo; }
            set { _Demo = value; }
        }

        private string _EmpName = string.Empty;
        [DataMember]
        public string EmpName
        {
            get { return _EmpName; }
            set { _EmpName = value; }
        }

        private int _KeyID ;
        [DataMember]
        public int KeyID
        {
            get { return _KeyID; }
            set { _KeyID = value; }
        }

        private string _Type = string.Empty;
        [DataMember]
        public string Type
        {
            get { return _Type; }
            set { _Type = value; }
        }

        private string _OrgType = string.Empty;
        [DataMember]
        public string OrgType
        {
            get { return _OrgType; }
            set { _OrgType = value; }
        }

        private string _Gender = string.Empty;
        [DataMember]
        public string Gender
        {
            get { return _Gender; }
            set { _Gender = value; }
        }

        private string _NowDuty = string.Empty;
        [DataMember]
        public string NowDuty
        {
            get { return _NowDuty; }
            set { _NowDuty = value; }
        }

        public static CheGaiModel FillEntity(DataRow dr)
        {
            CheGaiModel right = new CheGaiModel();
            //if (dr.Table != null && dr.Table.Columns.Contains("IsSelected"))
            //    right.IsSelected = dr["IsSelected"].ToString() == "false" ? false : true;
            right.IsSelected = dr["IsSelected"].ToString() == "false" ? false : true;
            if (dr.Table != null && dr.Table.Columns.Contains("ID")) right.ID = Convert.ToInt32(dr["ID"]);
            if (dr.Table != null && dr.Table.Columns.Contains("EmpID")) right.EmpID = Convert.ToInt32(dr["EmpID"]);
            if (dr.Table != null && dr.Table.Columns.Contains("Operator")) right.Operator = dr["Operator"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("OldZhiJi")) right.OldZhiJi = dr["OldZhiJi"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("OldJinE")) right.OldJinE = dr["OldJinE"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("ChangeDate") && !string.IsNullOrEmpty(dr["ChangeDate"].ToString())) right.ChangeDate = Convert.ToDateTime(dr["ChangeDate"]);

            if (dr.Table != null && dr.Table.Columns.Contains("NewZhiJi")) right.NewZhiJi = dr["NewZhiJi"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("NewJinE")) right.NewJinE = dr["NewJinE"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("CreateDate") && !string.IsNullOrEmpty(dr["CreateDate"].ToString())) right.CreateDate = Convert.ToDateTime(dr["CreateDate"]);
            if (dr.Table != null && dr.Table.Columns.Contains("Status")) right.Status = dr["Status"].ToString();

            if (dr.Table != null && dr.Table.Columns.Contains("RelationID") && !string.IsNullOrEmpty(dr["RelationID"].ToString())) right.RelationID = Convert.ToInt32(dr["RelationID"]);
            if (dr.Table != null && dr.Table.Columns.Contains("Demo")) right.Demo = dr["Demo"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("EmpName")) right.EmpName = dr["EmpName"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("KeyID")) if (!string.IsNullOrEmpty(dr["KeyID"].ToString())) right.KeyID = Convert.ToInt32(dr["KeyID"]);
            if (dr.Table != null && dr.Table.Columns.Contains("Type")) right.Type = dr["Type"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("OrgType")) right.OrgType = dr["OrgType"].ToString();

            if (dr.Table != null && dr.Table.Columns.Contains("Gender")) right.Gender = dr["Gender"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("NowDuty")) right.NowDuty = dr["NowDuty"].ToString();
            return right;
        }
    }
}
